﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace System.Data
{
    /// <summary>
    /// DataSet 扩展
    /// </summary>
    public static class DataSetExtension
    {
        /// <summary>
        /// 判断DataSet是否包含数据
        /// </summary>
        /// <param name="ds"></param>
        /// <returns></returns>
        public static Boolean HasData(this DataSet ds)
        {
            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                return true;
            }
            return false;
        }

        public static DataView AsDataView(this DataSet ds)
        {
            if (ds.HasData())
            {
                return ds.Tables[0].AsDataView();
            }
            return default(DataView);
        }

        public static EnumerableRowCollection<DataRow> AsEnumerable(this DataSet ds)
        {
            if (ds.HasData())
            {
                return ds.Tables[0].AsEnumerable();
            }
            return default(EnumerableRowCollection<DataRow>);
        }
    }
}
